package com.ant.cn.views;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.widget.TextView;

import com.ant.cn.R;

/**
 * Created by Administrator on 2016/12/5.
 */

public class MyAttrView01 extends TextView {
    private float lineHeight;
    private int lineColor;

    private Paint paint;


    public MyAttrView01(Context context) {
        super(context);
        initThisView(context, null, 0);
    }

    public MyAttrView01(Context context, AttributeSet attrs) {
        super(context, attrs);
        initThisView(context, attrs, 0);
    }

    public MyAttrView01(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        initThisView(context, attrs, defStyleAttr);
    }

    private void initThisView(Context context, AttributeSet attrs, int defStyleAttr) {
        attrConfig(context, attrs);
        paint = new Paint();
        paint.setColor(lineColor);
        paint.setStrokeWidth(lineHeight);
        paint.setStyle(Paint.Style.STROKE);

    }

    private void attrConfig(Context context, AttributeSet attrs) {
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.MyAttrView01);
        lineColor = ta.getColor(R.styleable.MyAttrView01_lineColor, 0);
        lineHeight = ta.getDimension(R.styleable.MyAttrView01_lingHeight, 0);
        ta.recycle();
    }

    @Override
    protected void onDraw(Canvas canvas) {
     canvas.drawRect(new RectF(0,0,getWidth(),getHeight()),paint);
        super.onDraw(canvas);
    }
}
